<?php

namespace App\Http\Controllers\Api\Third;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;
use DB;

//山东风控内网接口
class SdfkApiController extends Controller
{
    private $orgId = 1;
    private $status = 2;
    private $BaseUrl = "http://ip:port/";

    //查询风控平台存量工器具试验送检待检安全工器具信息
    public function getGqjBookTestInfo(){
        $url = $this->BaseUrl.'/rmcp-gqj-web/syzx/getGqjBookTestInfo';
        $postData = [
            'orgId'=>$this->orgId,
            'status'=>$this->status,
        ];
        $postData = json_encode($postData);
        $res = '{"code":0,"data":[{"bookid":"f75d0cf1d1b94d99815d47dda30ecd66","icode":"006080000000000000389646","gqjClass":"绝缘安全工器具","classid":"02","gqjClassify":"验电器","classifyid":"02001","factoryNum":"jn-bdycjxyb-YDQ-0016","gqjStandard":"GDY型,0.1-0.4kV","gqjStandardid":"02000999","voltageGrade":"","blgSgs":"国网济南供电公司","blgXgs":"","userGq":null,"useBsname":"变电检修中心","useBzname":"变电一次检修一班","useBzid":"ef8278bf225d11eb820d0242dfdc4669","useAddressName":"检修一班测试610","pkUserlocaleid":"1f44b4396fce4776b39f5c85f152a1a8","lastTestTime":"2021-06-08","nextTestTime":"2022-06-07","planName":"安全工器具历史采购批次","facName":"3M中国有限公司","factoryTime":"2021-06-01","creator":"刘昭","createTime":"2021-06-03","syxmInfo":[{"classifyid":"02001","gqjClassify":"验电器","pkDictDetailid":"1480740063402188801","value":"启动电压","testPeriod":"刘昭"},{"classifyid":"02001","gqjClassify":"验电器","pkDictDetailid":"1480740092288360449","value":"工频耐压试验","testPeriod":"12"}]}],"msg":"ok"}';
        $res = json_decode($res,true);
        // dd($res);
        // $res = json_decode(curl($url, $postData),true);

        if ($res['code'] == 0) {
            $data = $res['data'];
            $sampleWhere = [
                ['status0','<',2],
                ['third_id','!=',''],
            ];
            $sampleThird = DB::table('a_sample_info')->where($sampleWhere)->pluck('third_id')->toArray();
            $sampleData = [];
            if ($data) {
                foreach ($data as $key => $item) {
                    dd($item);
                    if (in_array($item['bookid'],$sampleThird)) {
                        continue;
                    }
                    $sampleData[] = [
                        'third_id' => $item['bookid'],
                        'manufacturer' => $item['facName'],
                        'production_date' => $item['factoryTime'],
                        'guige_xinghao' => $item['gqjStandard'],
                        'brand' => '',
                        'sample_status' => '外观无异常',
                    ];
                }
            }
        }else{
            
        }
    }

    //获取风控平台新购置工器具试验送检待检安全工器具信息
    public function getGqjStock(){
        $url = $this->BaseUrl.'/rmcp_gqj_web/syzx/getGqjStock';
        $postData = [
            'orgId'=>$this->orgId,
            'status'=>$this->status,
        ];
        $postData = json_encode($postData);
        return curl($url, $postData);
    }

    //检测存量工器具送检安全工器具试验结果保存
    public function saveGqjBookTestInfo($bookid,$sendmechanism,$testList){
        $url = $this->BaseUrl.'/rmcp_gqj_web/saveGqjBookTestInfo';
        $postData = [
            'orgId'=>$this->orgId,
            'status'=> 1,
            'bookid'=>$bookid,
            'sendmechanism'=>$sendmechanism,
            'testList'=>$testList,
        ];
        $postData = json_encode($postData);
        return curl($url, $postData);
    }

    // 检测新购置安全工器具试验结果保存
    public function saveStockTestInfo($bookid){
        $url = $this->BaseUrl.'/rmcp_gqj_web/saveStockTestInfo';
        $postData = [
            'status'=> 1,
            'bookid'=>$bookid,
            'sendmechanism'=>$sendmechanism,
            'testList'=>$testList,
        ];
        $postData = json_encode($postData);
        return curl($url, $postData);
    }

}
